TK!2
=v
#1
:n

:s
b
:c
** Root of equation by Regula Falsi **
#3
:n
fun
:v
'weird
:s
i
:c
function name
#4
:n
from
:v
2
:s
i
:c
lower limit of search interval
#5
:n
to
:v
8
:s
i
:c
upper limit of search interval
#6
:n
result
:v
4.831650560337041
:s
o
:c
root
=u
=l
=f
#1
:n
weird
:c
y = f(x)
:t
Rule
:a
x
:v
y
#2
:n
refal
:c
Regula falsi method
:t
Procedure
:i
fun,a,b
:o
x
#1
:n
weird
:z
y = x*ln(x/5) - sin(5*x)/5
/E
E
#2
:n
refal
:z
Notation:
" fun  - function name
" a,b  - limits of the search interval
" x    - root of the equation fun(x)=0

Description:
" The procedure represents a standard regula falsi method, i.e. reduction of
" the interval containing the root until the function value is smaller than
" a given limit (such as 1e-8, see the statement labeled test:).
" The procedure does not recognize when one of the original interval limits
" coincides exactly with the root. There is no built-in limit for the number
" of iteration steps.  The absence or ambiguity of roots within the search 
" interval is indicated by an error condition and message.

y0:= apply(fun,a)
y1:= apply(fun,b)
if sgn(y0)=sgn(y1) then error:= even_number_or_no_root_in_search_interval
loop: x:= a + (a-b)*y0/(y1-y0)
      y:= apply(fun,x)
      if sgn(y)=sgn(y1) goto newb
      a:= x
      y0:= y
      goto test
newb: b:= x
      y1:= y
test: if abs(y)<1e-8 return
      goto loop
/E
E
=r
#1
:r
result = refal(fun,from,to)     " used for finding the root
#3
:r
" The False Position (or Regula Falsi) method for finding a root of an
:s
C
#4
:r
" equation is usually slower than the Newton-Raphson method used by TK's
:s
C
#5
:r
" Iterative Solver, but it is less sensitive to the quality of the initial
:s
C
#6
:r
" guess.  The Iterative Solver fails to find the root of the above equation
:s
C
#7
:r
" even if the guess is as close as x=5 (look at the plots 'weird' and 
:s
C
#8
:r
" 'zoomed' in the model ROOTS\BISECT to see why).
:s
C
#9
:r
"                                                       [PgDn] for more
:s
C
#10
:r
" The procedure 'refal', given the search interval between 2 and 8, finds
:s
C
#11
:r
" the root in 39 steps going through  x = 3.939, 4.8798, 4.8669, 4.8568,
:s
C
#12
:r
" 4.8494, 4.8439, ..., 4.8316506 .  The convergence is actually slower than
:s
C
#13
:r
" with bisection or modified regula falsi (see the models BISECT and MREFAL)
:s
C
#14
:r
" due to the peculiar shape of the function graph in the root's vicinity.
:s
C
=p
=t
=n
=g
#1
:c
.000001
:i
1
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Tv,f,0,5,0,1,0
%Or,f,8,1,0,1,0
